package com.banshuibao.bsb_android.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by zyh on 2017/2/21.
 */

public class TimeUtil {

    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static SimpleDateFormat format1 = new SimpleDateFormat("MM-dd");
    private static SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat format3 = new SimpleDateFormat("HH:mm:ss");

    public static Date formatData(String dataString) {
        Date date = null;
        try {
            date = format.parse(dataString);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }


    public static String format(long timeStamp) {
        if (timeStamp == 0) {
            return "";
        }
        return format.format(new Date(timeStamp));

    }

    public static String format1(long timeStamp) {
        if (timeStamp == 0) {
            return "";
        }
        return format1.format(new Date(timeStamp));

    }

    public static String format2(long timeStamp) {
        if (timeStamp == 0) {
            return "";
        }
        return format2.format(new Date(timeStamp));

    }

    public static String format3(long timeStamp) {
        if (timeStamp == 0) {
            return "";
        }
        return format3.format(new Date(timeStamp));

    }

    /**
     * @param mss 要转换的毫秒数
     * @return 该毫秒数转换为 * days * hours * minutes * seconds 后的格式
     * @author fy.zhang
     */
    public static String formatDuring(long mss) {
        //int days =(int)( mss / (1000 * 60 * 60 * 24));
        String hours_tv, minutes_tv, seconds_tv;
        int hours = (int) ((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        int minutes = (int) ((mss % (1000 * 60 * 60)) / (1000 * 60));
        int seconds = (int) ((mss % (1000 * 60)) / 1000);
        if (hours <= 9) {
            hours_tv = "0" + hours;
        } else {
            hours_tv = String.valueOf(hours);
        }
        if (minutes <= 9) {
            minutes_tv = "0" + minutes;
        } else {
            minutes_tv = String.valueOf(minutes);
        }
        if (seconds <= 9) {
            seconds_tv = "0" + seconds;
        } else {
            seconds_tv = String.valueOf(seconds);
        }
        return hours_tv + ":" + minutes_tv + ":" + seconds_tv;
    }

    /**
     * @param mss 要转换的毫秒数
     * @return 该毫秒数转换为分钟
     */
    public static String formatMinutes(long mss) {
        String minutes_tv, seconds_tv;
        long minutes = mss / 60000;
        long seconds = mss / 1000 % 60;
        minutes_tv = String.valueOf(minutes);
        seconds_tv = String.valueOf(seconds);
        return minutes_tv + "分" + seconds_tv + "秒";
    }

    public static String getWeek(long timeStamp) {
        int mydate = 0;
        String week = null;
        Calendar cd = Calendar.getInstance();
        cd.setTime(new Date(timeStamp));
        mydate = cd.get(Calendar.DAY_OF_WEEK);
        // 获取指定日期转换成星期几
        if (mydate == 1) {
            week = "周期日";
        } else if (mydate == 2) {
            week = "星期一";
        } else if (mydate == 3) {
            week = "星期二";
        } else if (mydate == 4) {
            week = "星期三";
        } else if (mydate == 5) {
            week = "星期四";
        } else if (mydate == 6) {
            week = "星期五";
        } else if (mydate == 7) {
            week = "星期六";
        }
        return week;
    }
}
